package com.wbao.dianniu.logical;

import android.text.TextUtils;

import com.wbao.dianniu.emojiUtils.SharedPreferencedUtils;

/**
 * 全局变量
 *
 * @author yejianjun
 */
public class GlobalContext {

    public static final int NUMCOLUMNS = 3;

    private static String cacheToken = null;
    /**
     * 地址：定位到市
     */
    public static String address = "";

    //全局变量 缓存用户Id
    private static int cache_accountId = 0;
    //全局变量 cdnToken
    private static String cdnToken = null;
    //全局变量 cdndownUrl
    public static String cdndownUrl = "http://dianniu.image.alimmdn.com/images/";
    // 当前位置全局变量
    public static String curLocation = "";
    /**
     * 0：女  1：男 null: 未知
     */
    private static Integer sex = -1;

    public static boolean isExpand = false;

    private static GlobalContext instance;

    public GlobalContext instance() {
        if (null == instance) {
            instance = new GlobalContext();
        }
        return instance;
    }

    // token
    private static final String TOKEN_PREFERENCES = "token_preferences";
    // cdntoken
    private static final String CDNTOKEN_PREFERENCES = "cdntoken_preferences";
    // 默认0
    private static final String ACCOUNTID_PREFERENCES = "accountId_preferences";
    //  默认0
    private static final String MOBILE_PREFERENCES = "mobile_preferences";
    /**
     * 头像 默认null
     */
    private static final String HEADPIC_PREFERENCES = "headPic_preferences";
    /**
     * 昵称 默认null
     */
    private static final String NICENAME_PREFERENCES = "niceName_preferences";
    /**
     * 个性签名 默认null
     */
    private static final String SIGNATE_PREFERENCES = "signate_preferences";
    /**
     * 标签 默认null
     */
    private static final String LABEL_PREFERENCES = "label_preferences";
    /**
     * 0：女  1：男 null: 未知
     */
    private static final String SEX_PREFERENCES = "sex_preferences";

    /**
     * 是否完善资料 true： 是，false：否
     */
    private static final String ISPERFECTDATA_PREFERENCES = "isPerfectData_preferences";
    /**
     * 是否行业认证  true： 是，false：否
     */
    private static final String ISINDUSTRYAUTHORITY_PREFERENCES = "isIndustryAuthority_preferences";

    public static boolean getPerfectData() {
        return SharedPreferencedUtils.getBoolean(DnApplication.getContext(), ISPERFECTDATA_PREFERENCES, false);
    }

    public static void setPerfectData(boolean isPerfectData) {
        SharedPreferencedUtils.setBoolean(DnApplication.getContext(), ISPERFECTDATA_PREFERENCES, isPerfectData);
    }

    /**
     * 是否行业认证  true： 是，false：否
     */
    public static boolean getIndustryAuthority() {
        return SharedPreferencedUtils.getBoolean(DnApplication.getContext(), ISINDUSTRYAUTHORITY_PREFERENCES, false);
    }

    public static void setIndustryAuthority(boolean isIndustryAuthority) {
        SharedPreferencedUtils.setBoolean(DnApplication.getContext(), ISINDUSTRYAUTHORITY_PREFERENCES, isIndustryAuthority);
    }

    /**
     * 头像
     */
    public static String getHeadPic() {
        return SharedPreferencedUtils.getString(DnApplication.getContext(), HEADPIC_PREFERENCES, null);
    }

    public static void setHeadPic(String headPic) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), HEADPIC_PREFERENCES, headPic);
    }

    /**
     * 昵称
     */
    public static String getNiceName() {
        return SharedPreferencedUtils.getString(DnApplication.getContext(), NICENAME_PREFERENCES, null);
    }

    public static void setNiceName(String niceName) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), NICENAME_PREFERENCES, niceName);
    }

    /**
     * 个性签名
     */
    public static String getSignate() {
        return SharedPreferencedUtils.getString(DnApplication.getContext(), SIGNATE_PREFERENCES, null);
    }

    public static void setSignate(String signate) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), SIGNATE_PREFERENCES, signate);
    }

    /**
     * 标签
     */
    public static String getLabel() {
        return SharedPreferencedUtils.getString(DnApplication.getContext(), LABEL_PREFERENCES, null);
    }

    public static void setLabel(String label) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), LABEL_PREFERENCES, label);
    }

    public static Integer getSex() {
        if (sex == -1) {
            sex = SharedPreferencedUtils.getInteger(DnApplication.getContext(), SEX_PREFERENCES, -1);
        }
        return sex;
    }

    public static void setSex(Integer sexFlag) {
        if (null == sexFlag) {
            sex = -1;
        } else {
            sex = sexFlag;
        }
        SharedPreferencedUtils.setInteger(DnApplication.getContext(), SEX_PREFERENCES, sex);
    }

    public static String getCacheToken() {
        if (!TextUtils.isEmpty(cacheToken)) {
            return cacheToken;
        } else {
            cacheToken = SharedPreferencedUtils.getString(DnApplication.getContext(), TOKEN_PREFERENCES);
            return cacheToken;
        }
    }

    public static void cleanCacheToken() {
        cacheToken = null;
    }

    public static void setCacheToken(String token) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), TOKEN_PREFERENCES, token);
    }

    public static String getCdnToken() {
        if (TextUtils.isEmpty(cdnToken)) {
            cdnToken = SharedPreferencedUtils.getString(DnApplication.getContext(), CDNTOKEN_PREFERENCES);
        }
        return cdnToken;
    }

    public static void setCdnToken(String cdnToken) {
        SharedPreferencedUtils.setString(DnApplication.getContext(), CDNTOKEN_PREFERENCES, cdnToken);
    }

    public static int getAccountId() {
        if (0 == cache_accountId) {
            cache_accountId = SharedPreferencedUtils.getInteger(DnApplication.getContext(), ACCOUNTID_PREFERENCES, 0);
        }
        return cache_accountId;
    }


    public static void setAccountId(int accountId) {
        cache_accountId = accountId;
        SharedPreferencedUtils.setInteger(DnApplication.getContext(), ACCOUNTID_PREFERENCES, accountId);
    }

}
